<?php 
require_once "../funciones.php";
$_SESSION['caweb']['nit'] = "xxxxxxxxx";
$_SESSION['caweb']['factura'] ="";
?>

<html>
<head>
<title>Consulta FACTURAS</title>
<link rel="stylesheet" type="text/css" media="screen" href="themes/coffee/grid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="themes/jqModal.css" />
<link rel="StyleSheet" href="../css/redmond/jquery-ui-1.8.2.custom.css" type="text/css" />
<link rel="StyleSheet" href="../css/caweb.css" type="text/css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.js" type="text/javascript"></script>
<script src="js/jqModal.js" type="text/javascript"></script>
<script src="js/jqDnR.js" type="text/javascript"></script>
<script src="js/grid.subgrid.js" type="text/javascript"></script>
<script src="js/grid.locale-sp.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
<script src="js/jquery.ui.datepicker-es.js" type="text/javascript"></script>

<script type="text/javascript">
jQuery(document).ready(function(){
        $('#fecIni').datepicker({dateFormat:'yy-mm-dd'});
        $('#fecFin').datepicker({dateFormat:'yy-mm-dd'});
	jQuery("#list").jqGrid({
		url:"facturasProveedoresConsulta.php",
		datatype: 'xml',
		mtype: 'POST',
		colNames:['Cantidad','Factura','Proveedor','Descripcion Item','Vr. Unitario','Valor'],
		colModel :[ 
			{name:'cantidad',index:'cantidad', width:50,sortable:true},
                        {name:'factura',index:'factura', width:100,sortable:true},
			{name:'proveedor', index:'proveedor', width:300, sortable:true },
                        {name:'descripcion', index:'descripcion', width:300, sortable:true },
                        {name:'preciocompra', index:'preciocompra', width:120, align:"right", sortable:true },
  			{name:'valor', index:'valor', width:120, align:"right", sortable:true }
			], 
		editurl: "server.php",
		pager: jQuery('#pager'),
		rowNum:100000,
		rowList:[10,20,30,50],
		sortname: 'cantidad',
		sortorder: "DESC",
		viewrecords: true,
		theme: "Coffee",
		imgpath: 'themes/coffee/images',
		subGrid : true,
		subGridUrl: 'facturasProveedoresConsulta2.php',
    	subGridModel: [{ name  : ['No.','Serial','Sucursal','Bodega','Ubicacion','Vr. Unitario'],
                    width : [30,180,50,50,350,100] }
    	],
		caption: 'Entradas a Almacen', 
		height: 500
	});
	
	//Barra de navegacion
	jQuery("#list").navGrid('#pager',{
		edit:false, 
		add:false, 
		del:false, 
		search:false,
		view:false
	});
});

</script>

<script type="text/javascript">
function valida(){
    $.post('../pasasesion.php',{campo:'factura',valor:$("#factura").val()}, function () {
        $.post('../pasasesion.php',{campo:'nit',valor:$("#proveedor").val()}, function () {  
            $.post('../pasasesion.php',{campo:'fecIni',valor:$("#fecIni").val()}, function () {
                $.post('../pasasesion.php',{campo:'fecFin',valor:$("#fecFin").val()}, function () {  $('#list').trigger('reloadGrid');  });
            });
        });
    });
}
</script>
</head> 
<body>
	<br />
	<center>FACTURAS PROVEEDORES</center>
	<br />
    <?php
	$con = con_caweb();
        $sql ="SELECT nit,nombre FROM proveedores ORDER BY nombre";
	$proveedores=mysql_query($sql,$con) or die('Error proveedores, '.mysql_error().$sql);
    ?>
<!--        <form id="formProveedores" method="POST" action="">-->
        <label for="proveedor">Proveedor:</label>
        <select name="proveedor" id="proveedor" size="1" onchange="
//    $.post('../pasasesion.php',{campo:'proveedor',valor:this.value}, function () {
//        if ($('#factura').val() != '') { $('#list').trigger('reloadGrid'); }
//    });
	">
        <option value='' SELECTED>Todos</option>
	<?php while($row = mysql_fetch_array($proveedores)){	?>
            <option value="<? echo $row["nit"]; ?>" >  <? echo $row["nombre"]." -> ".$row["nit"]; ?> </option>
        <?php } ?>
        </select>
        <label for ="factura">Factura No.:</label>	  
        <input type="text" name="factura" id="factura" />
        <br />
        <label for="fecIni">Fecha Compra Inicial:</label><input type="text" id="fecIni" size="9"  />
        <label for="fecFin">Fecha Compra Final:</label><input type="text" id="fecFin" size="9"  /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Consultar" class="boton" onclick="return valida();" />
        <br/><br/>
<!--        </form>    -->
<div id="pager" class="scroll" style="text-align:center;"></div>
<table id="list" class="scroll"></table> 

</body>
</html>
